﻿using JobSearcherAPI.Models;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace JobSearcherAPI.Search
{
    internal class GitHubSearcher : JsonSearcher
    {
        const string BASE_URL = "http://jobs.github.com/positions.json?";
        const string DESCRIPTION = "description=";
        const string LOCATION = "&location=";

        protected override string CreateSearchAddress(SearchArguments arguments)
        {
            stringBuilder.Clear();
            stringBuilder
                .Append(BASE_URL)
                .Append(DESCRIPTION).Append(arguments.Keywords.UrlEncoded())
                .Append(LOCATION).Append(arguments.Location.UrlEncoded());
            return stringBuilder.ToString();
        }

        protected override void SetUpAttributeStrings()
        {
            date = "created_at";
            url = "company_url";
        }

        protected override void CreateToken(string json)
        {
            token = JArray.Parse(json);
        }
    }
}
